package com.example.designPattern.Proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/*
 * @Project:com.zh.DesignPattern.Proxy
 * @Creator:Administrator
 * @Description:
 * @Date Created in 11:29 2018/11/18
 */
public class DynamicProxyStarHandler implements InvocationHandler {
    private IStar realStar;

    public DynamicProxyStarHandler(IStar realStar) {
        this.realStar = realStar;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        switch (method.getName()) {
            case "confer":
                System.out.println("ProxyStar.confer()");
                break;
            case "signContract":
                System.out.println("ProxyStar.signContract()");
                break;
            case "bookTicket":
                System.out.println("ProxyStar.bookTicket()");
                break;
            case "sing":
                method.invoke(realStar, args);
                break;
            case "collectMoney":
                System.out.println("ProxyStar.collectMoney()");
                break;
        }

        return null;
    }
}
